<?php session_start(); ?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Experiment</title>
        <script src="timer.js"></script>

        <?php 
        
        $_SESSION['page_name']='Experiment'; include('Menu.php');
        $con= mysql_connect("localhost","root","");
        if(!$con){die('Connection Error!:' . mysql_error());}
        mysql_select_db ("usabilityevaluation",$con);
        $Participant=$_POST['Participant'];
        echo "<p>Participant number ".$Participant."</p>";
        $_SESSION['participant']=$Participant;
        //this query is for calculate time of an experiment;
        $exp_time=0;
        

    echo "</head>
    <body>";//<form method=\"post\" action=\"SaveExp.php\">";   
 

        //retreive the experimentation choose;
        $Title = $_POST['Title'];
        // Exp
        $query0 = "SELECT id_exp FROM experimentation WHERE Title='$Title'";
        $result = mysql_query($query0) or die('Error, retrieve query failed Exp');
        $id_exp = mysql_result($result, 0);
       
//Start Ouss
 //Start Ouss 
     //   $id_exp=$_SESSION['Exp_id'];
        $result222 = mysql_query("SELECT * FROM task WHERE id_experiment=$id_exp");
        echo"yuppi";
         // echo "<script>alert('".$id_exp."');</script>";
       while($row222=mysql_fetch_array($result222)){echo "jjj".$row222['Duration'];
       $exp_time += $row222['Duration'];
     
       }
          
        echo "<table  width='1358'><tr><td><input type='button' id='btnStart' value='Start count!' onClick='doTimer(60,60,".$exp_time.", ".$exp_time.")' align='right'  />
<input type='text' id='txt' align='right'/>
<input type='button' id='btnStop' value='Stop count!' onClick='stopCount()' align='right' /></td></td></table>";//Ouss
       //End Ouss

        // Task
        $query1 = "SELECT * FROM task WHERE id_experiment='$id_exp'";
        $result1 = mysql_query($query1) or die('Error, retrieve query failed Task');
        
       
        echo "<table>";
        //Task Loop
        while($row1 = mysql_fetch_array($result1)){
            //display task
            $id_task = $row1['id_task'];
            //Start Ouss
            echo "<form name='".$id_task."' method='post' action='SaveExp.php'>";
            $Task_number=1;$Question_number=1;
            //End Ouss
            echo "<tr><td>".$row1['Title']."</td></tr>";
            echo "<tr><td>[".$row1['Comment']."]</td></tr>";
            $q="q";
            //Question Loop
            $result2 = mysql_query("SELECT * FROM question WHERE id_task='$id_task' and id_exp='$id_exp'") ;
            while($row2 = mysql_fetch_array($result2)){$answer=1;//Ouss
                //display question
                $id_question = $row2['id_question'];
                $Type=$row2['Type'];//Ouss
                echo "<tr><td><table><tr><td>&nbsp;&nbsp;&nbsp;</td><td>".$row2['Title']."</td></tr>";
                // Answer
                $query3 = "SELECT * from answers where id_question='$id_question'";
                $result3 = mysql_query($query3) or die('Error, retreive Answer query failed');                
                while($row3 = mysql_fetch_array($result3)){
                    //display answer 
                 
                    echo "<tr><td>&nbsp;&nbsp;&nbsp;</td>
                              <td><table><tr><td>&nbsp;&nbsp;&nbsp;</td>";
                              
                    if ($row2['Type']=='Multiple Choice'){
                        echo "<input type='checkbox' name='". $id_question."q".$row3[0]."' value='".$row3['title']."'/> ";
                           echo $row3['title']; // show beside checbox
                    }
                    if ($row2['Type']=='Text to Fill'){
                        echo "<input type='text' name='".$id_question."q".$row3[0]."'/>";
                        echo $row3['title']; // show beside checbox
                    }
                    if ($row2['Type']=='Ratingscale'){
                        echo "<input type='radio' name='answer' value=". $row3['title']."/>".$row3['title'];
                        echo $row3['title']; // show beside scale
                    }
                    if ($row2['Type']=='TrueFalse'){
                        echo "<input type=\"radio\" name='".$id_question."' value=\"True\" /> True
                        <input type=\"radio\" name'".$id_question."' value=\"False\" /> False " ;                     
                        // echo $row3['title']; // show beside radio
                    }
                    echo "</td></tr></table></td></tr>";
                }
                echo "</table>";
            $Question_number ++;$answer ++;//Ouss}
        
       
        }//Ouss}
        echo "</table>";  
            echo "<tr><td align='right'><input type=\"submit\" value=\"Save\"/></td></tr></td></tr>";
         echo "</form>"; $Task_number ++; 
         }
        mysql_close($con);
        ?>
        <input type="submit" value="SaveAll" />
       <!--  </form> -->
    </body>
</html>


